import dt from '@dt/dt'
import server from '@/config/server'

function post(path, auth = true, config = true) {
  return server.api().post(path).auth(auth).config(config)
}

function get(path, auth = true, config = true) {
  return server.api().get(path).auth(auth).config(config)
}

const api = {
  del: get('/dt-order/bo/stdDetail/special/delBonusStdDetailSpecial/[bonusDetailId]'),
  clear: get('/dt-order/bo/stdDetail/special/emptyBonusStdDetailSpecial/[bonusId]'),
  export: get('/dt-order/bo/stdDetail/special/exportBonusStdDetailSpecialList/[bonusId]').tag(
    'downloadCenter'
  ),
  downloadRoom: server.api().download('/dt-order/bo/stdDetail/special/exportsBonusStdDetailSpecial'),
  importRoom: server.api().upload('/dt-order/bo/stdDetail/special/importBonusStdDetailSpecial'),
  roomList: post('/dt-order/bo/stdDetail/special/selectBonusStdDetailSpecialList'),
  submit: post('/dt-order/bo/stdDetail/special/submitBonusStdDetailSpecial'),
  roomEdit: post('/dt-order/bo/stdDetail/special/updateBonusStdDetailSpecial')
}

function del(bonusDetailId) {
  //
  return api.del.fetch({
    bonusDetailId
  })
}

function clear(bonusId) {
  return api.clear.fetch({
    bonusId
  })
}

function exportInfo(bonusId) {
  return api.export.fetch({
    bonusId
  })
}

function downloadRoom() {
  return api.downloadRoom.fetch({
    housesId: dt.buildInfo().housesId,
    fileName: '特殊奖金单模板.xls'
  })
}

function importRoom(bonusId) {
  let info = { bonusId }
  info.housesId = dt.buildInfo().housesId
  info.fileName = 'file'
  let upload = api.importRoom
  upload.setData(info)
  return upload
}

function roomList(bonusId, data) {
  data.bonusId = bonusId
  return api.roomList.fetch(data)
}

function submit(data) {
  return api.submit.fetch(data)
}

function roomEdit(bonusDetailId, shouldBonusAmount) {
  return api.roomEdit.fetch({
    bonusDetailId,
    shouldBonusAmount
  })
}

export default {
  del,
  clear,
  exportInfo,
  downloadRoom,
  importRoom,
  roomList,
  submit,
  roomEdit
}
